package com.fsnbigdata.web;

import com.fsnbigdata.domain.ZhKopu;
import com.fsnbigdata.service.api.ZhkopuService;
import io.swagger.annotations.Api;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.roo.addon.web.mvc.controller.annotations.ControllerType;
import org.springframework.roo.addon.web.mvc.controller.annotations.RooController;
import org.springframework.roo.addon.web.mvc.controller.annotations.responses.json.RooJSON;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Collection;

/**
 * 生物科普控制类
 * @Author: chen quan zhou
 * @Date: Created in 10:29 2018/8/28
 * @Modified By:
 */

@RooController(entity = ZhKopu.class, pathPrefix = "/api", type = ControllerType.COLLECTION)
@RooJSON
@RestController
@RequestMapping(value = "/api/zhkopu",name = "ZhkopuController", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(tags = "Zhkopu", description = "生物科普首页" )
public class ZhkopuController {

    @Autowired
    private ZhkopuService zhkopuService;


    @RequestMapping(value = "findkopu",name = "findkopu")
    public ZhKopu findKopu(){
        return zhkopuService.findById(1);
    }
    
    @PutMapping(value = "updatekopu", name = "updatekopu")
    public ResponseEntity<?> update(@Valid @RequestBody ZhKopu zhKopus, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResponseEntity.status(HttpStatus.CONFLICT).body(bindingResult);
        }
        return ResponseEntity.ok(zhkopuService.update(zhKopus));
    }

    
}
